package threadPool;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @program: javase
 * @description: 线程池
 * @author: lld
 * @create: 2021-05-31 20:20
 **/
public class MyPool1 {
    public static void main(String[] args) throws InterruptedException, IOException {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(2, 5,
                3, TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(5), new ThreadPoolExecutor.CallerRunsPolicy());
        for (int i = 0; i < 12; i++) {
            executor.execute(() -> System.out.println(Thread.currentThread().getName() + ":do"));
            Thread.sleep(10000);
        }
        executor.shutdown();

        InputStreamReader inputStreamReader = new InputStreamReader(new InputStream() {
            @Override
            public int read() {
                return 2;
            }
        });
        System.out.println(inputStreamReader.read());
    }
}
